<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class search_model extends WST_Model {
	private $_table = "post";

	function find_all($keyword,$page_size = 20, $page_number = 1){
        $where =" WHERE `status`=1 AND locked=0";
        if(!empty($keyword)){
            $where.=" AND ( name LIKE '%".$keyword."%' OR content LIKE '%".$keyword."%' )";
        }
        $sql = "SELECT * from ".$this->_table. $where."   order by modifyTime DESC";
        if ($page_number > 0 && $page_size > 0) {
            $offset = ($page_number-1)* $page_size;
            $sql .= " limit {$offset}, {$page_size}";
        }
        $query = $this->db->query($sql);
        $data=$query->result_array();
        $query->free_result();
        return $data;
	}

	function count_all($keyword){
        $this->db->where('status',1);
        $this->db->where('locked',0);
        $this->db->like('name',$keyword);
        $this->db->or_like('content',$keyword);
		return $this->db->count_all_results($this->_table);
	}

}
